﻿using System.ComponentModel;
using System.Linq;
using Ext.Net;

namespace KamLib.Controls
{

    public static class DefaultCss
    {
        public const string HBoxes_DefaultMargins = "0 30px 0 0";
        public const string HBoxes_DefaultMargins2_1 = "0 30px 0 0";
        public const string HBoxes_DefaultMargins2_2 = "0 0  0 30px";

        public const string Padding1 = "20px 20px 20px 30px";
        public const string Padding11 = "10px 20px 20px 30px";
        public const string Padding2 = "10px 10px 10px 10px";
    }

    #region Containers

    #region Boxes

    public class HBoxes : HBox
    {
        /// <summary>
        ///  The margins to apply by default to each field in the composite
        /// </summary>
        [Category("6. KamLib")]
        [DefaultValue(DefaultCss.HBoxes_DefaultMargins)]
        [NotifyParentProperty(true)]
        [Description("The margins to apply by default to each item in the HBoxes")]
        public string DefaultMargins { get { return _DefaultMargins; } set { _DefaultMargins = value; } }
        private string _DefaultMargins = DefaultCss.HBoxes_DefaultMargins;

        /// <summary>
        /// If true, the DefaultMargins are not applied to the last item in the composite field set (defaults to true)
        /// </summary>
        [Category("6. KamLib")]
        [DefaultValue(true)]
        [NotifyParentProperty(true)]
        [Description("If true, the defaultMargins are not applied to the last item in the HBoxes set (defaults to true)")]
        public bool SkipLastItemMargin { get { return _SkipLastItemMargin; } set { _SkipLastItemMargin = value; } }
        bool _SkipLastItemMargin = true;

        protected override void OnPreRender(System.EventArgs e)
        {
            foreach (var item in Items.Take(Items.Count - (SkipLastItemMargin ? 1 : 0)).OfType<BoxComponentBase>())
            {
                item.Margins = DefaultMargins;
            }
            base.OnPreRender(e);
        }
    }

    public class HBoxes2 : HBox
    {
        /// <summary>
        ///  The margins to apply by default to each field in the composite
        /// </summary>
        [Category("6. KamLib")]
        [DefaultValue(DefaultCss.HBoxes_DefaultMargins2_1)]
        [NotifyParentProperty(true)]
        [Description("The margins to apply by default to each item in the HBoxes")]
        public string DefaultMargins1 { get { return _DefaultMargins1; } set { _DefaultMargins1 = value; } }
        private string _DefaultMargins1 = DefaultCss.HBoxes_DefaultMargins2_1;

        /// <summary>
        ///  The margins to apply by default to each field in the composite
        /// </summary>
        [Category("6. KamLib")]
        [DefaultValue(DefaultCss.HBoxes_DefaultMargins2_2)]
        [NotifyParentProperty(true)]
        [Description("The margins to apply by default to Last item in the HBoxes")]
        public string DefaultMargins2 { get { return _DefaultMargins2; } set { _DefaultMargins2 = value; } }
        private string _DefaultMargins2 = DefaultCss.HBoxes_DefaultMargins2_2;

        /// <summary>
        /// If true, the DefaultMargins are not applied to the last item in the composite field set (defaults to true)
        /// </summary>
        [Category("6. KamLib")]
        [DefaultValue(true)]
        [NotifyParentProperty(true)]
        [Description("If true, the defaultMargins are not applied to the last item in the HBoxes set (defaults to true)")]
        public bool SkipLastItemMargin { get { return _SkipLastItemMargin; } set { _SkipLastItemMargin = value; } }
        bool _SkipLastItemMargin = true;

        protected override void OnPreRender(System.EventArgs e)
        {
            if (Items.Count > 0)
            {
                if (SkipLastItemMargin)
                {
                    foreach (var item in Items.Take(Items.Count - 1).OfType<BoxComponentBase>())
                    {
                        item.Margins = DefaultMargins1;
                        item.Cls += " kl-box-vrr";
                    }
                    var item2 = Items[Items.Count - 1] as BoxComponentBase;
                    if (item2 != null) item2.Margins = DefaultMargins2;
                }
                else
                    foreach (var item in Items.OfType<BoxComponentBase>())
                    {
                        item.Margins = DefaultMargins1;
                        item.Cls += " kl-box-vrr";
                    }
            }

            base.OnPreRender(e);
        }
    }

    public class VBoxes : VBox
    {
        /// <summary>
        ///  The margins to apply by default to each field in the composite
        /// </summary>
        [Category("6. KamLib")]
        [DefaultValue("10px 0 0 0")]
        [NotifyParentProperty(true)]
        [Description("The margins to apply by default to each item in the VBoxes")]
        public string DefaultMargins { get { return _DefaultMargins; } set { _DefaultMargins = value; } }
        private string _DefaultMargins = "10px 0 0 0";

        /// <summary>
        /// If true, the DefaultMargins are not applied to the last item in the composite field set (defaults to true)
        /// </summary>
        [Category("6. KamLib")]
        [DefaultValue(true)]
        [NotifyParentProperty(true)]
        [Description("If true, the defaultMargins are not applied to the last item in the HBoxes set (defaults to true)")]
        public bool SkipLastItemMargin { get { return _SkipLastItemMargin; } set { _SkipLastItemMargin = value; } }
        bool _SkipLastItemMargin = true;

        protected override void OnPreRender(System.EventArgs e)
        {
            foreach (var item in Items.Take(Items.Count - (SkipLastItemMargin ? 1 : 0)).OfType<BoxComponentBase>())
            {
                item.Margins = DefaultMargins;
            }
            base.OnPreRender(e);
        }
    }

    #endregion


    #region Padding1

    public class Padding1 : LayoutContainer
    {
        [DefaultValue("kl-pd-p1")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p1"); }
            set { base.Cls = value; }
        }
    }

    public class Padding1Accordion : Accordion
    {
        [DefaultValue("kl-pd-p1")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p1"); }
            set { base.Cls = value; }
        }
    }

    public class Padding1Anchor : Anchor
    {
        [DefaultValue("kl-pd-p1")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p1"); }
            set { base.Cls = value; }
        }
    }

    public class Padding1Fit : Fit
    {
        [DefaultValue("kl-pd-p1")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p1"); }
            set { base.Cls = value; }
        }
    }

    public class Padding1Form : Form
    {
        [DefaultValue("kl-pd-p1")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p1"); }
            set { base.Cls = value; }
        }
    }

    public class Padding1HBox : HBox
    {
        [DefaultValue("kl-pd-p1")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p1"); }
            set { base.Cls = value; }
        }
    }

    public class Padding1HBoxes : HBoxes
    {
        [DefaultValue("kl-pd-p1")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p1"); }
            set { base.Cls = value; }
        }
    }

    public class Padding1VBox : VBox
    {
        [DefaultValue("kl-pd-p1")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p1"); }
            set { base.Cls = value; }
        }
    }

    public class Padding1VBoxes : VBoxes
    {
        [DefaultValue("kl-pd-p1")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p1"); }
            set { base.Cls = value; }
        }
    }

    #endregion


    #region Padding2

    public class Padding2 : LayoutContainer
    {
        [DefaultValue("kl-pd-p2")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p2"); }
            set { base.Cls = value; }
        }
    }

    public class Padding2Accordion : Accordion
    {
        [DefaultValue("kl-pd-p2")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p2"); }
            set { base.Cls = value; }
        }
    }

    public class Padding2Anchor : Anchor
    {
        [DefaultValue("kl-pd-p2")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p2"); }
            set { base.Cls = value; }
        }
    }

    public class Padding2Fit : Fit
    {
        [DefaultValue("kl-pd-p2")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p2"); }
            set { base.Cls = value; }
        }
    }

    public class Padding2Form : Form
    {
        [DefaultValue("kl-pd-p2")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p2"); }
            set { base.Cls = value; }
        }
    }

    public class Padding2HBox : HBox
    {
        [DefaultValue("kl-pd-p2")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p2"); }
            set { base.Cls = value; }
        }
    }

    public class Padding2HBoxes : HBoxes
    {
        [DefaultValue("kl-pd-p2")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p2"); }
            set { base.Cls = value; }
        }
    }

    public class Padding2VBox : VBox
    {
        [DefaultValue("kl-pd-p2")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p2"); }
            set { base.Cls = value; }
        }
    }

    public class Padding2VBoxes : VBoxes
    {
        [DefaultValue("kl-pd-p2")]
        public override string Cls
        {
            get { return ViewState.Try("Cls", "kl-pd-p2"); }
            set { base.Cls = value; }
        }
    }

    #endregion

    #endregion


    #region Panels

    #region Boxes

    public class HBoxesPanel : HBoxPanel
    {
        /// <summary>
        ///  The margins to apply by default to each field in the composite
        /// </summary>
        [Category("6. KamLib")]
        [DefaultValue(DefaultCss.HBoxes_DefaultMargins)]
        [NotifyParentProperty(true)]
        [Description("The margins to apply by default to each item in the HBoxes")]
        public string DefaultMargins { get { return _DefaultMargins; } set { _DefaultMargins = value; } }
        private string _DefaultMargins = DefaultCss.HBoxes_DefaultMargins;

        /// <summary>
        /// If true, the DefaultMargins are not applied to the last item in the composite field set (defaults to true)
        /// </summary>
        [Category("6. KamLib")]
        [DefaultValue(true)]
        [NotifyParentProperty(true)]
        [Description("If true, the defaultMargins are not applied to the last item in the HBoxes set (defaults to true)")]
        public bool SkipLastItemMargin { get { return _SkipLastItemMargin; } set { _SkipLastItemMargin = value; } }
        bool _SkipLastItemMargin = true;

        protected override void OnPreRender(System.EventArgs e)
        {
            foreach (var item in Items.Take(Items.Count - (SkipLastItemMargin ? 1 : 0)).OfType<BoxComponentBase>())
            {
                item.Margins = DefaultMargins;
            }
            base.OnPreRender(e);
        }
    }

    public class HBoxes2Panel : HBoxPanel
    {
        /// <summary>
        ///  The margins to apply by default to each field in the composite
        /// </summary>
        [Category("6. KamLib")]
        [DefaultValue(DefaultCss.HBoxes_DefaultMargins2_1)]
        [NotifyParentProperty(true)]
        [Description("The margins to apply by default to each item in the HBoxes")]
        public string DefaultMargins1 { get { return _DefaultMargins1; } set { _DefaultMargins1 = value; } }
        private string _DefaultMargins1 = DefaultCss.HBoxes_DefaultMargins2_1;

        /// <summary>
        ///  The margins to apply by default to each field in the composite
        /// </summary>
        [Category("6. KamLib")]
        [DefaultValue(DefaultCss.HBoxes_DefaultMargins2_2)]
        [NotifyParentProperty(true)]
        [Description("The margins to apply by default to Last item in the HBoxes")]
        public string DefaultMargins2 { get { return _DefaultMargins2; } set { _DefaultMargins2 = value; } }
        private string _DefaultMargins2 = DefaultCss.HBoxes_DefaultMargins2_2;

        /// <summary>
        /// If true, the DefaultMargins are not applied to the last item in the composite field set (defaults to true)
        /// </summary>
        [Category("6. KamLib")]
        [DefaultValue(true)]
        [NotifyParentProperty(true)]
        [Description("If true, the defaultMargins are not applied to the last item in the HBoxes set (defaults to true)")]
        public bool SkipLastItemMargin { get { return _SkipLastItemMargin; } set { _SkipLastItemMargin = value; } }
        bool _SkipLastItemMargin = true;

        protected override void OnPreRender(System.EventArgs e)
        {
            if (Items.Count > 0)
            {
                if (SkipLastItemMargin)
                {
                    foreach (var item in Items.Take(Items.Count - 1).OfType<BoxComponentBase>())
                    {
                        item.Margins = DefaultMargins1;
                        item.Cls += " kl-box-vrr";
                    }
                    var item2 = Items[Items.Count - 1] as BoxComponentBase;
                    if (item2 != null) item2.Margins = DefaultMargins2;
                }
                else
                    foreach (var item in Items.OfType<BoxComponentBase>())
                    {
                        item.Margins = DefaultMargins1;
                        item.Cls += " kl-box-vrr";
                    }
            }

            base.OnPreRender(e);
        }
    }

    public class VBoxesPanel : VBoxPanel
    {
        /// <summary>
        ///  The margins to apply by default to each field in the composite
        /// </summary>
        [Category("6. KamLib")]
        [DefaultValue("10px 0 0 0")]
        [NotifyParentProperty(true)]
        [Description("The margins to apply by default to each item in the VBoxes")]
        public string DefaultMargins { get { return _DefaultMargins; } set { _DefaultMargins = value; } }
        private string _DefaultMargins = "10px 0 0 0";

        /// <summary>
        /// If true, the DefaultMargins are not applied to the last item in the composite field set (defaults to true)
        /// </summary>
        [Category("6. KamLib")]
        [DefaultValue(true)]
        [NotifyParentProperty(true)]
        [Description("If true, the defaultMargins are not applied to the last item in the HBoxes set (defaults to true)")]
        public bool SkipLastItemMargin { get { return _SkipLastItemMargin; } set { _SkipLastItemMargin = value; } }
        bool _SkipLastItemMargin = true;

        protected override void OnPreRender(System.EventArgs e)
        {
            foreach (var item in Items.Take(Items.Count - (SkipLastItemMargin ? 1 : 0)).OfType<BoxComponentBase>())
            {
                item.Margins = DefaultMargins;
            }
            base.OnPreRender(e);
        }
    }

    #endregion


    #region Padding1Panel

    public class Padding1Panel : LayoutPanel
    {
        [DefaultValue(DefaultCss.Padding1)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding1); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding1AccordionPanel : AccordionPanel
    {
        [DefaultValue(DefaultCss.Padding1)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding1); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding1AnchorPanel : AnchorPanel
    {
        [DefaultValue(DefaultCss.Padding1)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding1); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding1FitPanel : FitPanel
    {
        [DefaultValue(DefaultCss.Padding1)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding1); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding1FormPanel : FormLayoutPanel
    {
        [DefaultValue(DefaultCss.Padding1)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding1); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding1HBoxPanel : HBoxPanel
    {
        [DefaultValue(DefaultCss.Padding1)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding1); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding1HBoxesPanel : HBoxesPanel
    {
        [DefaultValue(DefaultCss.Padding1)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding1); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding1HBoxes2Panel : HBoxes2Panel
    {
        [DefaultValue(DefaultCss.Padding1)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding1); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding1VBoxPanel : VBoxPanel
    {
        [DefaultValue(DefaultCss.Padding1)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding1); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding1VBoxesPanel : VBoxesPanel
    {
        [DefaultValue(DefaultCss.Padding1)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding1); }
            set { base.PaddingSummary = value; }
        }
    }

    #endregion


    #region Padding11Panel

    public class Padding11Panel : LayoutPanel
    {
        [DefaultValue(DefaultCss.Padding11)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding11); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding11AccordionPanel : AccordionPanel
    {
        [DefaultValue(DefaultCss.Padding11)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding11); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding11AnchorPanel : AnchorPanel
    {
        [DefaultValue(DefaultCss.Padding11)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding11); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding11FitPanel : FitPanel
    {
        [DefaultValue(DefaultCss.Padding11)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding11); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding11FormPanel : FormLayoutPanel
    {
        [DefaultValue(DefaultCss.Padding11)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding11); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding11HBoxPanel : HBoxPanel
    {
        [DefaultValue(DefaultCss.Padding11)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding11); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding11HBoxesPanel : HBoxesPanel
    {
        [DefaultValue(DefaultCss.Padding11)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding11); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding11HBoxes2Panel : HBoxes2Panel
    {
        [DefaultValue(DefaultCss.Padding11)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding11); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding11VBoxPanel : VBoxPanel
    {
        [DefaultValue(DefaultCss.Padding11)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding11); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding11VBoxesPanel : VBoxesPanel
    {
        [DefaultValue(DefaultCss.Padding11)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding11); }
            set { base.PaddingSummary = value; }
        }
    }

    #endregion

    
    #region Padding2

    public class Padding2Panel : LayoutPanel
    {
        [DefaultValue(DefaultCss.Padding2)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding2); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding2AccordionPanel : AccordionPanel
    {
        [DefaultValue(DefaultCss.Padding2)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding2); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding2AnchorPanel : AnchorPanel
    {
        [DefaultValue(DefaultCss.Padding2)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding2); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding2FitPanel : FitPanel
    {
        [DefaultValue(DefaultCss.Padding2)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding2); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding2FormPanel : FormLayoutPanel
    {
        [DefaultValue(DefaultCss.Padding2)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding2); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding2HBoxPanel : HBoxPanel
    {
        [DefaultValue(DefaultCss.Padding2)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding2); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding2HBoxesPanel : HBoxesPanel
    {
        [DefaultValue(DefaultCss.Padding2)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding2); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding2HBoxes2Panel : HBoxes2Panel
    {
        [DefaultValue(DefaultCss.Padding2)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding2); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding2VBoxPanel : VBoxPanel
    {
        [DefaultValue(DefaultCss.Padding2)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding2); }
            set { base.PaddingSummary = value; }
        }
    }

    public class Padding2VBoxesPanel : VBoxesPanel
    {
        [DefaultValue(DefaultCss.Padding2)]
        public override string PaddingSummary
        {
            get { return ViewState.Try("PaddingSummary", DefaultCss.Padding2); }
            set { base.PaddingSummary = value; }
        }
    }

    #endregion

    #endregion


}
